Xbasic

SELECT ... CASE ... END SELECT

Syntax

SELECT [ CASE Logical_Expression1 [ Statements1 ]] [ CASE Logical_Expression2 [ StatementsN ]] ... [ CASE Logical_ExpressionN [ Statements1 ]] CASE else [ StatementsN ]] END SELECT

Arguments

Logical_Expression1 ... Logical_ExpressionN

Optional. One or more expressions that evaluate to .T. (TRUE) or .F. (FALSE).

Statements1 ... StatementsN

Optional. A set of one or more statements paired with a corresponding logical expression, to be executed if the logical expression evaluates to .T. (TRUE).

Statements ... StatementsN

Optional. A set of one or more statements that execute in the default case, if no other statement evaluates to .T. (TRUE).

Description

Conditional control structure comprised of one or more CASE statements.

Discussion

SELECT ... CASE is a conditional control structure comprised of one or more CASE statements. The Logical Expression of each CASE statement is evaluated until a TRUE result is reached. The statements for the TRUE CASE are executed, and program flow continues after the end SELECT. The statements listed after the CASE else are executed as the default action if no other CASE expression is TRUE. Note : Because SELECT ... CASE spans multiple lines, it cannot be used in an expression. However, the CASE() function will achieve the same result, and may be used in an expression.

Example

Associate a grade with a score. Any score below 60 is an F.

function test_grade as C(score as N)
    SELECT
        CASE score >= 90
            grade = "A"
        CASE score >= 80
            grade = "B"
        CASE score >= 70
            grade = "C"
        CASE score >= 60
            grade = "D"
        CASE else
            grade = "F"
    end SELECT
    test_grade = grade
end function

See Also